import qs from 'qs'

export default {
  baseURL: window.gConfig.baseURL,
  baseURL1: window.gConfig.baseURL1,
  uploadURL: window.gConfig.uploadURL,
  imagesUrl: window.gConfig.imagesUrl
}

/**
 * 下载方法
 * @param url 下载接口地址
 * @param data 请求数据
 * */
export const downloadToTagByA = function (url, data) {
  const downloadForm = document.createElement('form')
  downloadForm.style = "display:none;"
  downloadForm.method = "post"
  downloadForm.action = window.gConfig.uploadURL + url + '?' + qs.stringify(data)
  document.body.appendChild(downloadForm)
  downloadForm.submit()
  document.body.removeChild(downloadForm)
}

/**
 * 自定义上传
 * @param {*} fileobj
 */
export function fileUpload(fileobj) {
  let param = new FormData();
  // 上传文件对象 名称file与后台控制器参数要一致
  param.append('file', fileobj.file);
  return request({
    method: 'post',
    // 上传地址
    url: '/goods-service/goods/sku/file',
    // 定义上传头
    headers: {'Content-Type': 'multipart/form-data'},
    data: param
  });


}

